package hot100;

import DTO.TreeNode;

public class isValidBST {
    long pre = Long.MIN_VALUE;

    public boolean isValidBST(TreeNode root) {
        if(root == null) {
            return true;
        }
        boolean left = isValidBST(root.left);

        //剪枝
        if(left == false) return false;

        boolean cur = false;
        if(root.val > pre) {
            cur = true;
        }

        //剪枝
        if(cur == false) return false;

        pre = root.val;
        boolean right = isValidBST(root.right);
        return right && left && cur;
    }
}
